﻿using System.Web;
using System.Web.Mvc;
using Smarly.Web.Areas.StapleForum.Controllers;
using Smarly.Web.RouteConstraints;

namespace Smarly.Web.Areas.StapleForum
{
	public class StapleForumAreaRegistration : AreaRegistration
	{
		public override string AreaName
		{
			get
			{
				return "StapleForum";
			}
		}

		private const string subdomain = "staple";

		public override void RegisterArea(AreaRegistrationContext routes)
		{

			routes.MapRoute(
					"StapleForum_SectionCrumb",
					"StapleForum_SectionCrumb/{section}",
					new { controller = "Section", action = "Crumbs", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(SectionController).Namespace }
				);

			routes.MapRoute(
					"StapleForum_EditThreadNote",
					"thread/editnote/{Id}",
					new { controller = "Thread", action = "EditNote", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(ThreadController).Namespace }
				);

			routes.MapRoute(
					"StapleForum_EditThreadNoteClarify",
					"thread/editnoteclarify/{Id}",
					new { controller = "Thread", action = "EditClarify", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(ThreadController).Namespace }
				);

			routes.MapRoute(
					"StapleForum_CreateThread",
					"{section}/create",
					new { controller = "Thread", action = "Create", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(ThreadController).Namespace }
				);

			routes.MapRoute(
					"StapleForum_Thread",
					"{section}/thread{id}/{name}",
					new { controller = "Thread", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional, subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint(), id = @"\d+" },
				new[] { typeof(ThreadController).Namespace }
				);

			routes.MapRoute(
					"Thread_AddClarify",
					"thread/addclarify/{ThreadNoteId}",
					new { controller = "Thread", action = "AddClarify", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(ThreadController).Namespace }
				);

			routes.MapRoute(
					"Thread_AddNote",
					"thread/addnote",
					new { controller = "Thread", action = "AddNote", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(ThreadController).Namespace }
				);


			#region Account

			routes.MapRoute(
				"StapleForum_SignInAccountDialog",
				"dialog/account",
				new { controller = "Account", action = "Index", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"StapleForum_CreateAccountDialog",
				"dialog/account/create",
				new { controller = "Account", action = "Create", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"StapleForum_RepearAccountDialog",
				"dialog/account/repear",
				new { controller = "Account", action = "Repear", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"StapleForum_UpdateAccountDialog",
				"dialog/account/update/{hashcode}",
				new { controller = "Account", action = "UpdatePassword", hashcode = UrlParameter.Optional, subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"StapleForum_SignOutAccount",
				"account/logout",
				new { controller = "Account", action = "Logout", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(AccountController).Namespace }
				);

			routes.MapRoute(
				"StapleForum_Account_UserInfo",
				"account/{emailsh1}",
				new { controller = "Account", action = "UserInfo", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(AccountController).Namespace }
				);

			#endregion


			routes.MapRoute(
					"StapleForum_default",
					"",
					new { controller = "Home", action = "Index", subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(HomeController).Namespace }
				);

			routes.MapRoute(
					"StapleForum_section",
					"{section}",
					new { controller = "Home", action = "Section", id = UrlParameter.Optional, subdomain = subdomain },
				new { subdomain = new DomainRouteConstraint() },
				new[] { typeof(HomeController).Namespace }
				);
		}
	}
}
